/*
 * BooleanNode.cpp
 *
 *  Created on: 28/dic/2010
 *      Author: computer
 */

#include "DerivationTree.h"
#include "CallInstruction.h"


BooleanNode::BooleanNode() : NodeTree_CRTP<BooleanNode>() { }

BooleanNode::BooleanNode(const AutoPointer<NodeTree>& _left, const AutoPointer<NodeTree>& _right, const AutoPointer<NodeTree>& _symbol) : NodeTree_CRTP<BooleanNode>(), left(_left), right(_right), symbol(_symbol) { }

BooleanNode::BooleanNode(const BooleanNode& copy) : NodeTree_CRTP<BooleanNode>(copy), left(copy.left), right(copy.right), symbol(copy.symbol) { }

bool BooleanNode::execute(Pointer<LeonardVirtualMachine> LVM) {
	right->execute(LVM);
	left->execute(LVM);
	AutoPointer<TreeExpression::Expression> first = LVM->top();//TODO order
	LVM->pop();
	AutoPointer<TreeExpression::Expression> second = LVM->top();
	LVM->pop();
	first->addLeaf(second);
	symbol->execute(LVM);
	AutoPointer<TreeExpression::Expression> ris = LVM->top();//Load the boolean function on the stack
	ris->setSon(first);
	return true;
}
